<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="${base}/rs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${base}/rs/bootstrap-fileinput/css/fileinput.min.css" />

    <script src="${base}/rs/jquery/jquery-1.12.4.min.js"></script>
    <script src="${base}/rs/bootstrap-fileinput/js/fileinput.min.js"></script>
    <script src="${base}/rs/bootstrap-fileinput/js/locales/zh.js"></script>
    <script src="${base}/rs/bootstrap/js/bootstrap.min.js"></script>
    <script src="${base}/rs/js/layer/layer.js"></script>
    <script src="${base}/rs/js/layer/commont.js"></script>

    <script type="text/javascript">
        function initFileInput(ctrlName) {
            var control = $('#' + ctrlName);
            control.fileinput({
                language: 'zh',
                uploadUrl: '${base}/file/fileUpload',
                allowedFileExtensions : ['jpg', 'png','gif'],
                dropZoneEnabled: true,//是否显示拖拽区域
                dropZoneTitle:"可以拖拽图片到这里,快到碗里来!!!",
                dropZoneClickTitle:"",
                zoomModalHeight: 280,
                overwriteInitial: false,
                maxFileSize: 1000,
                maxFilesNum: 10,
                showUploadedThumbs: false,
                showCaption: false,
                showUpload: false,
                browseClass: "btn green btn-outline sbold", //按钮样式
                removeClass:"btn red btn-outline sbold",
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                showPreview :true,
                //默认支持多文件上传
                multiple: true,
                uploadAsync: true,
                enctype: 'multipart/form-data',
            })
        }
        //初始化就调用该方法
        $(function () {
            initFileInput("file");
            /*$("#file").on("fileuploaded", function (event, data, previewId, index) {
                var obj = data.response;//
                alert(JSON.stringify(obj.errorMsg));
            });*/
        })

        function updateOrAdd(){
            //上传，通过ajax
            var formData = new FormData($( "#id_item_form" )[0]);
            $.ajax({
                type: "POST",
                url: "${base}/sysOss/UpdateOrAddEntity",
                data: formData,
                contentType: false,
                processData: false,
                success: function(result){
                    if(1==result.returnInfo.state) {
                        layer.msg('操作成功', {icon: 6,time: 3*1000});
                        /*var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.$('#table').bootstrapTable("refresh");
                        parent.layer.close(index);*/
                        var url="${base}/sysOss/listPage";
                        parent.window.location.href=url;
                    }
                },
                error: function(){
                    layer.msg('操作失败', {icon: 6,time: 3*1000});
                }
            });
        }
    </script>
</head>
<body>
    <form id="id_item_form" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <div class="col-sm-4">
                <input id="file" name="myfiles" type="file" multiple data-show-caption="true">
            </div>
        </div>

        <div class="form-actions">
            <div class="col-sm-4">
                <button type="button" onclick="parentLayerClose()" class="btn btn-default">取消</button>
                &nbsp;&nbsp;
                <button type="button" onclick="updateOrAdd()" class="btn btn-primary">确定</button>
            </div>

        </div>
    </form>
    <script>

    </script>
</body>
</html>